160. 相交链表

https://leetcode.cn/problems/intersection-of-two-linked-lists/description/?orderBy=most_votes&languageTags=c


1.有交点，a遍历完去b上。b遍历完去a上  会同时经过节点

2.无交点，会同时到NULL


struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) 
{
    if(headA==NULL||headB==NULL)
    {
        return NULL;
    }
     struct ListNode*pA=headA;
     struct ListNode*pB=headB;
     while(pA!=pB)
     {
         if(pA==NULL)
         {
             pA=headB;
         }
         else
         {
             pA=pA->next;
         }

         if(pB==NULL)
         {
             pB=headA;
         }
         else
         {
             pB=pB->next;
         }
     }

     return pA;
    
}